package net.qiqb.ddd.user.application;

import lombok.extern.slf4j.Slf4j;
import net.qiqb.core.executing.annotation.BusinessIdVoucher;
import net.qiqb.core.executing.annotation.Command;
import net.qiqb.core.executing.annotation.HandleBusiness;
import net.qiqb.ddd.user.domain.UserAggregateRoot;
import net.qiqb.execute.UserId;

@Slf4j
@Command(UserAggregateRoot.class)
public class UserNameModifyCmd {

    //@BusinessIdVoucher
    private UserId userId;

    @BusinessIdVoucher
    private String account;

    private final String name;

    public UserNameModifyCmd(UserId userId, String name) {
        this.name = name;
        this.account = name;
        this.userId = userId;
    }

    public UserNameModifyCmd(String name) {
        this.name = name;
    }

    @HandleBusiness
    public void modifyName(UserAggregateRoot userEntity) {
        log.info("修改用户名称：{} -> {}", userEntity.getUserName(), this.name);
        userEntity.changeName(name);
    }
}
